#include "sprite.h"

void Sprite::draw() const { 
  Uint32 x = static_cast<Uint32>(getX());
  Uint32 y = static_cast<Uint32>(getY());
  frame->draw(x, y); 
}

void Sprite::update(Uint32 ticks) { 
  float incr = getYSpeed() * static_cast<float>(ticks) * 0.001;
  setY( getY() + incr);
  int height = frame->getHeight();
  if ( getY() < 0) {
    setY( 1.0 );
    setYSpeed( abs(getYSpeed()) );
  }
  if ( getY() > screenHeight-height) {
    setY( static_cast<float>(screenHeight-height) );
    setYSpeed( -abs(getYSpeed()) );
  }

  incr = getXSpeed() * static_cast<float>(ticks) * 0.001;
  setX(getX()+ incr);
  float width = static_cast<float>(frame->getWidth());
  if ( getX() < 0) {
    setX( 1.0 );
    setXSpeed( abs(getXSpeed()) );
  }
  if ( getX() > screenWidth-width) {
    setX( static_cast<float>(screenWidth-width) );
    setXSpeed( -abs(getXSpeed()) );
  }
}
